
#include "lv_demo_encoder.h"
#include "lv_port_indev.h"
#include <lvgl.h>
#include "images.h"
 

lv_obj_t *wc_scr[4];

// lv_obj_t *weather_image = NULL;
// lv_obj_t *cityname_label = NULL;
lv_obj_t *temperature_label = NULL;
// lv_obj_t *time_image = NULL;
lv_obj_t *time_image1 = NULL;
lv_obj_t *date_label = NULL;
lv_obj_t *time_label = NULL;




lv_font_declare(lv_font_montserrat_24);
lv_font_declare(lv_font_montserrat_40);

  static lv_style_t default_style;
    static lv_style_t label_style1;
    static lv_style_t label_style2;
  
const void *image_map[] = {&bukaixin, &kaixin};
int map_index[] = {0, 1};
const void *image_map1[] = {&qika,&yitou,&remen,&mi,&sipi,&wutu,&liuk};
int map_index1[] = {0, 1,2,3,4,5,6};









void weather_gui_init(void)
{   lv_style_reset(&default_style);
    lv_style_init(&default_style);
    lv_style_set_bg_color(&default_style, LV_STATE_DEFAULT, LV_COLOR_BLACK);
    lv_style_set_bg_color(&default_style, LV_STATE_PRESSED, LV_COLOR_GRAY);
    lv_style_set_bg_color(&default_style, LV_STATE_FOCUSED, LV_COLOR_BLACK);
    lv_style_set_bg_color(&default_style, LV_STATE_FOCUSED | LV_STATE_PRESSED, lv_color_hex(0xf88));

   wc_scr[0] = lv_scr_act();
    lv_obj_add_style(wc_scr[0], LV_BTN_PART_MAIN, &default_style);
    lv_style_reset(&label_style1);
    lv_style_init(&label_style1);
    lv_style_set_text_opa(&label_style1, LV_STATE_DEFAULT, LV_OPA_COVER);
    lv_style_set_text_color(&label_style1, LV_STATE_DEFAULT, LV_COLOR_WHITE);
    lv_style_set_text_font(&label_style1, LV_STATE_DEFAULT, &lv_font_montserrat_24);
   
    wc_scr[1] = lv_obj_create(NULL,NULL);
    lv_obj_add_style(wc_scr[1], LV_BTN_PART_MAIN, &default_style);
    lv_style_reset(&label_style2);
    lv_style_init(&label_style2);
    lv_style_set_text_opa(&label_style2, LV_STATE_DEFAULT, LV_OPA_COVER);
    lv_style_set_text_color(&label_style2, LV_STATE_DEFAULT, LV_COLOR_WHITE);
    lv_style_set_text_font(&label_style2, LV_STATE_DEFAULT, &lv_font_montserrat_40);
    wc_scr[2] = lv_obj_create(NULL,NULL);
    lv_obj_add_style(wc_scr[2], LV_BTN_PART_MAIN, &default_style);
    
}





void display_weather_time(const char *page, const char *temperature,const char *date, const char *time,int weed,lv_scr_load_anim_t anim_type)
{


   
   
    
  
    lv_obj_clean(wc_scr[0]); // 清空此前页面
     // weather_image = lv_img_create(wc_scr[0], NULL);
    // cityname_label = lv_label_create(wc_scr[0], NULL);
    temperature_label = lv_label_create(wc_scr[0], NULL);
    // time_image = lv_img_create(wc_scr[0], NULL);
    time_image1 = lv_img_create(wc_scr[0], NULL);
    date_label = lv_label_create(wc_scr[0], NULL);
    time_label = lv_label_create(wc_scr[0], NULL);
   
  
  
    // lv_img_set_src(weather_image,&tian);
    // lv_obj_align(weather_image, NULL, LV_ALIGN_OUT_TOP_MID, 60, 180);

    // lv_obj_add_style(cityname_label, LV_LABEL_PART_MAIN, &label_style1);
    // lv_label_set_text(cityname_label, page);
    // lv_obj_set_pos(cityname_label,0,80);

    lv_obj_add_style(temperature_label, LV_LABEL_PART_MAIN, &label_style2);
    lv_label_set_text_fmt(temperature_label, "%s°C", temperature);
    lv_obj_align(temperature_label, NULL, LV_ALIGN_OUT_TOP_MID, 60, 190);
    
     
    // lv_img_set_src(time_image, &timll);
    // lv_obj_align(time_image, NULL, LV_ALIGN_OUT_TOP_MID, 60, 110);
    const void *path ;
    if(weed < 7){
      path = image_map1[map_index1[weed]];
      
      }
    
    
    lv_img_set_src(time_image1, path);
    lv_obj_set_pos(time_image1,0,0);

    lv_obj_add_style(date_label, LV_LABEL_PART_MAIN, &label_style2);
    lv_label_set_text(date_label, date);
    lv_obj_align(date_label, NULL, LV_ALIGN_OUT_BOTTOM_LEFT, 15, -95);

    lv_obj_add_style(time_label, LV_LABEL_PART_MAIN, &label_style2);
    lv_label_set_text(time_label, time);
    lv_obj_align(time_label, NULL, LV_ALIGN_OUT_BOTTOM_LEFT, 15, -50);

    lv_scr_load_anim(wc_scr[0], anim_type, 300, 300, false);


  
    
    
}
void displaybg1( lv_scr_load_anim_t anim_type){

lv_obj_clean(wc_scr[1]);
lv_obj_t* img1 = lv_img_create(wc_scr[1], NULL);
lv_img_set_src(img1, &bg);
lv_obj_align(img1, NULL, LV_ALIGN_CENTER, 0, 0);
lv_scr_load_anim(wc_scr[1], anim_type, 300, 300, false);


}
void displaybg(lv_scr_load_anim_t anim_typer1){
lv_obj_clean(wc_scr[2]);
lv_obj_t* img2 = lv_img_create(wc_scr[2], NULL);
lv_img_set_src(img2, &bg1);
lv_obj_align(img2, NULL, LV_ALIGN_CENTER, 0, 0);
lv_scr_load_anim(wc_scr[2], anim_typer1, 300, 300, false);



}